<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>物业管理系统</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
</head>
<style>
</style>
<body style="padding-bottom: 90px; background-color: #ECF0F5;">
	<div class="modal-content">
		<div class="modal-body">
			<div class="form-group">
				<label class="control-label">编号：</label> <input type="text" class="form-control" id="number" onBlur="checkingNumber()">
			</div>
			<div class="form-group">
				<label for="describe" class="control-label">名称：</label> <input type="text" class="form-control" id="regionName">
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/js/date.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script>
	var lock = false;
	var id = "${map['id']}";
	var index = parent.layer.getFrameIndex(window.name);
	var checkNumber=false;
	$(function() {
		if (id != '') {
			$.ajax({
				url : "${pageContext.request.contextPath}/selectParkingRegionById",
				type : "post",
				data : {
					id : id
				},
				dataType : "json",
				success : function(map) {
					var parkingRegion = map['parkingRegion'];
					$("#number").val(parkingRegion.number);
					$("#regionName").val(parkingRegion.regionName);
				}
			});
		}
	});
	
	function checkingNumber(){
		checkNumber=false;
		if(id==''){
			$.ajax({
				url : "${pageContext.request.contextPath}/checkingNumber",
				type : "post",
				data : {
					number : $("#number").val()
				},
				dataType : "json",
				success : function(data) {
					var result = data['result'];
					if (result == 0) {
						checkNumber=true;
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 2,
						time : 800
					});
				}
			});
		}
	}

	//添加或修改
	function insertData() {
		lock = true;
		var number = $("#number").val();
		var regionName = $("#regionName").val();
		if (number === '' || regionName === '') {
			layer.alert("请填写名称，编号!");
			lock = false;
			return;
		}
		if(checkNumber){
			layer.alert("编号重复!");
			lock = false;
			return;
		}
		var url= id === '' ? '${pageContext.request.contextPath}/insertParkingRegion' : '${pageContext.request.contextPath}/updateParkingRegion'; 
		$.ajax({
			url : url,
			type : "post",
			data : {
				id : id,
				number : number,
				regionName : regionName
			},
			dataType : "json",
			success : function(data) {
				var result = data['result'];
				if (result == 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						parent.query();
						parent.layer.close(index);
					}, 1000);
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
					lock = false;
				}
			}
		});
	}

	function insert() {
		if (!lock) {
			insertData();
		}
	}
</script>
</html>
